*
* This program illustrates relation between CONVOLUTION and CORRELATION
*
* Correlation is equivalent to convolution with Flipped array
*
#define NPTS 8
#define TMAX (NPTS-1)

      Program fex2
      Integer i
      real seq1(0:TMAX), seq2(0:TMAX), cor1(0:TMAX), cor2(0:TMAX)

* Initialize Sequences ... seq2 is seq1 shifted by two samples
      seq1(0) = 0.
      seq1(1) = 0.
      seq2(TMAX-1) = 0.
      seq2(TMAX  ) = 0.
      
      do i = 2, TMAX
	seq1(i) = 10. * ( -.3 ** i)
	seq2(i-2) = seq1(i)
      end do
* Correlation
      call scor1d( seq1,1,0,NPTS,seq2,1,0,NPTS,cor1,1,0,NPTS)

* Convolution with flipped array
* We actually just call sfir1d with the flipping parameters
* New origin of array is last sample, new increment is -(old increment)
      call sfir1d(seq1,1,0,NPTS,seq2(TMAX),-1,-TMAX,NPTS,
     $		    cor2,1,0,NPTS,1.0,0.0)

* Print out the Input sequences and the Correlation functions
      write(6,11)
      write(6,12) seq1(0:TMAX)
      write(6,13)
      write(6,12) seq2(0:TMAX)
      write(6,14)
      write(6,12) cor1(0:TMAX)
      write(6,15)
      write(6,12) cor2(0:TMAX)
 11   format('Seq # 1 : ')
 12   format(8f9.5)
 13   format('Seq # 2 : ')
 14   format('Correlation using \"scor1d\" : ')
 15   format('Correlation using \"sfir1d\" : ')
      stop
      end
